<?php

namespace Common\Service;


/** 
 * 消息
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

Class MessageService extends BaseService
{
	
	

	/** 
		type : 消息类型;    [ zan 点赞 | at 提到 | comment 评论]  
		target_id:  对应的对象ID;
		uid : 操作用户ID
		to  : 发送给的USER ID
		create_time: 操作时间
		status: 消息状态  [ 0 unread, 1 read ]

		 点赞:  type: 'zan', target_id: {video_id}, uid: {uid},
		 提到:  type: 'at', target_id: {video_id}, uid: {uid},  
		 评论:  type: 'comment', target_id: {video_id}, uid: {uid}, 
	*/

	static $types = array('zan', 'at', 'comment');

	const STATUS_UNREAD  = 0;	// 未读
	const STATUS_READ 	 = 1;	// 已读
	const STATUS_DEL  	 = -1;  // 删除 delete

	protected $_auto = array(
        array('uid', 'intval', self::MODEL_INSERT, 'function'),
        array('target_id', 'intval', self::MODEL_INSERT, 'function'),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('status', self::STATUS_UNREAD, self::MODEL_INSERT),
    );  
	
	public function send($type, $target_id, $uid,  $to)
	{
		if (!in_array($type, self::$types))
		{
			return;
		}

		$data['type'] 		= $type;
		$data['target_id'] 	= intval($target_id);
		$data['uid'] 		= intval($uid);
		$data['to'] 		= intval($to);
		$data = $this->create($data);
		$this->add($data);
	}



}